package rabbitmq.A08springboot;

import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Administrator
 * @Date: 2023/2/17 11:59
 */

@RestController
@RequestMapping("/simple/second")
@AllArgsConstructor//这个注解会使rabbitTemplate 通过构造器注入
public class SecondQueueProducer {
    private RabbitTemplate secondTemplate;
    // 发送到的队列名称
    public static final String AMQP_SIMPLE_QUEUE = "amqp.simple.queue";

    /**
     * 发送简单消息
     * @param message 消息内容
     */
    @GetMapping("/sendMessage")
    public String sendMessage(@RequestParam(value = "message") String message){
        secondTemplate.convertAndSend(AMQP_SIMPLE_QUEUE, message);
        return "OK";
    }
}
